package com.example.ibeetl.controller;

import com.alibaba.fastjson.JSON;
import com.sun.xml.internal.ws.policy.sourcemodel.ModelNode;
import org.beetl.core.GroupTemplate;
import org.beetl.ext.fn.Json;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.example.ibeetl.model.User;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName DemoController
 * @Description
 * @Author zhangsw
 * @Date 2020/12/10 22:25
 * @Version 1.0
 */
@Controller
@RequestMapping("demo")
public class DemoController {

    @GetMapping("demo1")
    public ModelAndView demo1(HttpSession session) {
        List<User> users = Arrays.asList(new User("aa", 11), new User("bb", 12));
        session.setAttribute("userList", users);
        ModelAndView mv = new ModelAndView();
        mv.addObject("username", "张三");
        mv.addObject("users", users);
        mv.addObject("users2", JSON.toJSONString(users));

        HashMap<String, String> map = new HashMap<>();
        map.put("k1", "vwasd");
        map.put("k2", "SADNJ");
        mv.addObject("map", map);
        mv.setViewName("demo1");
        return mv;
    }

    @GetMapping("demo2")
    public ModelAndView demo2() {
        List<User> users = Arrays.asList(new User("aa", 11), new User("bb", 12));
        ModelAndView mv = new ModelAndView();
        mv.addObject("currentDate", new Date());
        mv.addObject("users", users);
        mv.setViewName("demo2");
        return mv;
    }
}